package top.mataiji.manager.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.mataiji.manager.service.OrderService;
import top.mataiji.manager.service.User_moneyServer;
import top.mataiji.manager.util.Result;

/**
 * @Auther: zhaoss
 * @Date: 2021/4/16 - 04 - 16 - 10:44
 * @Description: top.mataiji.manager.controller
 * @version: 1.0
 */
@RestController
@RequestMapping("user_money")
public class User_moneyController {

    @Autowired
    User_moneyServer user_moneyServer;
    @Autowired
    OrderService orderService;

    /**
     * 查询用户钱包余额
     * @param userId
     * @return
     */
    @RequestMapping("selectByUserId/{userId}")
    public Long selectMoneyByUserId(@PathVariable("userId") Integer userId){
        return user_moneyServer.selectMoneyByUserId(userId);
    }

    @RequestMapping("payMoney")
    @Transactional
    public Result pay(String orderId, Long orderPrice, Integer userId){
        //修改订单状态
        Integer i1 =  orderService.alertOrderStatus(orderId);
        Integer i2 = user_moneyServer.pay(orderPrice,userId);
        if(i1>0&&i1!=null&&i2>0&&i2!=null){
            return Result.success("支付成功");
        }
        return Result.error("支付失败");
    }

}
